<template>
  <div id="main">
    <!-- 面包屑 -->
    <div class="breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>{{ obj.parentName }}</el-breadcrumb-item>
        <el-breadcrumb-item>{{ obj.name }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 导航 -->
    <div class="nav">
      <div class="nav_tit">
        <div class="nav_tit_left">
          <span>品牌</span>
        </div>
        <div class="nav_tit_right">
          <ul>
            <li class="active" @click="onLi($event)">全部</li>
            <li v-for="item in obj.brands" :key="item.id" @click="onLi($event)">
              {{ item.name }}
            </li>
          </ul>
        </div>
      </div>
      <div class="nav_tit" v-for="item in obj.saleProperties" :key="item.id">
        <div class="nav_tit_left">
          <span>{{ item.name }}</span>
        </div>
        <div class="nav_tit_right">
          <ul>
            <li class="active" @click="onLi($event)">全部</li>
            <li
              v-for="items in item.properties"
              :key="items.id"
              @click="onLi($event)"
            >
              {{ items.name }}
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!-- 主体部分 -->
    <div class="content"></div>
  </div>
</template>

<script>
export default {
  name: "NavItem",
  data() {
    return {
      //获取来的数据
      obj: {},
      //content数据
      list: [],
    };
  },
  mounted() {
    this.$api.getNav(1005009).then((res) => {
      // console.log(res.data.result)
      this.obj = res.data.result;
    });
    /* content部分 */
    this.$api
      .getNavLi({
        page: 1,
        pageSize: 20,
        categoryId: 1005009,
      })
      .then((res) => {
        console.log(res);
        this.list = res;
      })
      .catch((err) => {
        console.log(err);
      });
  },
  methods: {
    //选中样式
    onLi(e) {
      for (let i = 0; i < e.target.parentElement.children.length; i++) {
        e.target.parentElement.children[i].classList.remove("active");
      }
      e.target.classList.add("active");
      this.$api
        .getNavLi({
          page: 1,
          pageSize: 20,
          categoryId: 1005009,
        })
        .then((res) => {
          console.log(res);
          this.list = res;
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang='scss' scoped>
#main {
  width: 66%;
  outline: 1px solid red;
  margin: 0 auto;
  overflow: hidden;
  .breadcrumb {
    margin: 25px 0;
  }
  /* 导航 */
  .nav {
    width: 100%;
    background: white;
    font-size: 14px;
    padding: 20px;
    box-sizing: border-box;
    .nav_tit {
      display: flex;
      flex-wrap: wrap;
      margin-bottom: 20px;
      .nav_tit_left {
        color: #ccc;
        width: 10%;
      }
      .nav_tit_right {
        width: 90%;
        box-sizing: border-box;
        ul {
          display: flex;
          flex-wrap: wrap;
          li {
            margin-right: 30px;
            width: 120px;
            height: 30px;
            line-height: 30px;
            text-align: start;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
          .active {
            color: #27bb9a;
          }
        }
      }
    }
  }
  /* 主体部分 */
  .content {
    width: 100%;
    background: white;
    margin-top: 30px;
    padding-top: 30px;
  }
}
</style>